package prototype;

public class PrototypePattern {

    public static void main(String[] args) {
        // 圆原型
        Circle circle = new Circle();
        circle.setRadius(5);

        // 正方形原型
        Square square = new Square();
        square.setWidth(10);

        // 长方形原型
        Rectangle rectangle = new Rectangle();
        rectangle.setWidth(4);
        rectangle.setHeight(3);

        // 形状注册表
        ShapeRegistry registry = ShapeRegistry.getInstance();
        registry.addShape("circle", circle);
        registry.addShape("square", square);
        registry.addShape("rectangle", rectangle);

        // 克隆一个圆
        Shape c = registry.getShape("circle");
        c.draw();
        // 克隆一个正方形
        Shape s = registry.getShape("square");
        s.draw();
        // 克隆一个长方形
        Shape r = registry.getShape("rectangle");
        r.draw();
    }
}
